package com.jvxb.manage.livable.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jvxb.manage.livable.entity.SysRolePerm;
import com.jvxb.manage.livable.service.SysRolePermService;
import com.jvxb.common.utils.CommonUtil;
import com.jvxb.common.web.RespMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色-权限映射表 前端控制器
 * </p>
 *
 * @author jvxb
 * @since 2020-06-07
 */
@RestController
@RequestMapping("/admin/v1/sysRolePerm")
public class SysRolePermController {

    @Autowired
    private SysRolePermService rolePermService;

    @GetMapping("getRolePermByRoleId")
    public RespMsg<List> getRolePermByRoleId(@RequestParam Integer roleId) {
        List perms = new ArrayList();
        List<SysRolePerm> list = rolePermService.list(new QueryWrapper<SysRolePerm>().eq(SysRolePerm.ROLE_ID, roleId));
        if(CommonUtil.notNullOrEmpty(list)) {
            for(SysRolePerm rolePerm : list) {
                perms.add(rolePerm.getPermId());
            }
        }
        return RespMsg.ok(perms);
    }

}

